package auto;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

public class SouthPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2348938864806052494L;

	private JButton dugmePretraga = null;
	private JButton dugmeKasa = null;
	private JButton dugmeRegistracija = null;

	// private Helper hlp = new Helper();

	GridBagLayout gbl = new GridBagLayout();
	GridBagConstraints gbc = new GridBagConstraints();

	public SouthPanel() {

		setLayout(gbl);
		add(getPretragaDugme());
		add(getKasaDugme());
		add(getRegistracijaDugme());
	}

	// ********************************************** geter za Pretraga dugme

	private JButton getPretragaDugme() {
		if (dugmePretraga == null) {
			dugmePretraga = new JButton();
			dugmePretraga.setIcon(loadIcon("/icons/Search.png"));
			
			gbcXY(0, 0);
			gbl.setConstraints(dugmePretraga, gbc);
				if(Var.ulogaID1==1)
				dugmePretraga.setEnabled(false);
				
				dugmePretraga.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent arg0) {
					
						
					}
				});
		}
		return dugmePretraga;

	}

	// ********************************************** geter za Kasa dugme

	private JButton getKasaDugme() {
		if (dugmeKasa == null) {
			dugmeKasa = new JButton();
			dugmeKasa.setIcon(loadIcon("/icons/cash1.png"));
			gbcXY(1, 0);
			gbl.setConstraints(dugmeKasa, gbc);
			if(Var.ulogaID1==1)
			dugmePretraga.setEnabled(false);

		}
		return dugmeKasa;

	}

	private JButton getRegistracijaDugme() {
		if (dugmeRegistracija == null) {
			dugmeRegistracija = new JButton();
			dugmeRegistracija.setIcon(loadIcon("/icons/Users.png"));
			gbcXY(2, 0);
			gbl.setConstraints(dugmeRegistracija, gbc);
			dugmeRegistracija.addActionListener(new ActionListener(
					) {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					JDialog di = new RegistracijaKorisnika();
					di.setVisible(true);
					di.setAlwaysOnTop(true);
				}
			});
			

		}
		return dugmeRegistracija;

	}

	public void gbcXY(int x, int y) {
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.insets = new Insets(15, 15, 15, 15);
	}

	public ImageIcon loadIcon(String path) {
		return new ImageIcon(getClass().getResource(path));
	}

}
